<template>
  <div class="form">
    <el-form :model="form" label-width="120px">
      {{ form }}
      <!-- {{ fieldList }} -->
      <template v-for="(item, index) in fieldList" :key="index">
        <!-- 默认输入框 -->
        <el-form-item v-if="item.type == 'input'" :label="item.label">
          <el-input v-model="form[item.field]"></el-input>
        </el-form-item>
        <!-- 下拉选择 -->
        <el-form-item v-if="item.type == 'select'" :label="item.label">
          <el-select v-model="form[item.field]" placeholder="select">
            <el-option v-for="(option, optionIndex) in item.options" :label="option.label" :value="option.value"
              :key="optionIndex">
            </el-option>
          </el-select>
        </el-form-item>
      </template>


      <!-- 按钮 -->
      <el-form-item>
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleComfirm">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">

const props = defineProps({
  fieldList: [],
  form: {}
})

// const form: Record<string, any> = ref({})


// watch(() => form.name, () => {
//   console.log(form.name)
// })

const emits = defineEmits(["handleClose", "handleComfirm"])
const handleClose = () => {
  emits("handleClose")
}
const handleComfirm = () => {
  emits("handleComfirm", props.form)
}

</script>

<style scoped>

</style>